package com.goodfox.web.generic.log.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.RowBounds;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.goodfox.web.generic.account.entity.Account;
import com.goodfox.web.generic.log.entity.OperatorLog;
import com.goodfox.web.generic.log.mapper.OperatorLogMapper;
import com.goodfox.web.generic.log.service.LogService;
import com.goodfox.web.generic.login.entity.LoginLog;
import com.goodfox.web.generic.login.mapper.LoginLogMapper;
import com.goodfox.web.generic.provide.annotation.NoteExplain;
import com.goodfox.web.generic.provide.entity.Pager;
import com.goodfox.web.generic.provide.util.DateUtil;

/**
 * 日志Service实现类
 * @author qin gt
 *
 */
@Transactional
@Service(value="logService")
@NoteExplain(comment="日志管理")
public class LogServiceImpl implements LogService {
	
	/** log4j日志器 */
	private Logger logger=Logger.getLogger(LogServiceImpl.class);

	/** 日志Mapper */
	@Autowired
	private OperatorLogMapper operatorLogMapper;
	
	/** 登录日志Mapper */
	@Autowired
	private LoginLogMapper loginLogMapper;

	@NoteExplain(comment="查询登录日志列表")
	public Pager<LoginLog> queryLoginLogPager(int currentPage,int numPerPage,Map map){
		int start=(currentPage-1)*numPerPage;
		Long allCount=loginLogMapper.selectLoginLogListCount(map);
		List<LoginLog> list=loginLogMapper.selectLoginLogList(map,new RowBounds(start, numPerPage));
		return new Pager<LoginLog>(allCount,list);
	}
	
	@NoteExplain(comment="获取登录日志")
	public LoginLog queryLoginLog(String lgnLogId){
		return loginLogMapper.selectLoginLogById(lgnLogId);
	}
	
	/**
	 * 根据组织机构Id获取账户（列表）
	 * @param organizationId
	 * @return
	 */
	public List<Account> queryAccountListByOrgaId(String orgId){
		return operatorLogMapper.queryAccountListByOrgaId(orgId);
	}

	@NoteExplain(comment="查询操作日志列表")
	public Pager<OperatorLog> queryOperatorLogPager(int currentPage,int numPerPage,Map map){
		int start=(currentPage-1)*numPerPage;
		Long allCount=operatorLogMapper.selectOperatorLogListCount(map);
		List<OperatorLog> list=operatorLogMapper.selectOperatorLogList(map,new RowBounds(start, numPerPage));
		return new Pager<OperatorLog>(allCount,list);
	}

	@NoteExplain(comment="查询操作日志")
	public OperatorLog getOperatorLog(String opeLogId){
		return operatorLogMapper.selectOperatorLogById(opeLogId);
	}
	

}
